package uz.edo.db.utils;

import uz.edo.utils.Constants;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: said
 * Date: 1/13/12
 * Time: 11:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class DBObject implements Serializable, Constants {
    private Integer objectID = new Integer(0);

    public Integer getObjectID() {
        return objectID;
    }

    public void setObjectID(Integer objectID) {
        this.objectID = objectID;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) return false;
        if (!(o instanceof DBObject))
            return false;
        DBObject gco = (DBObject) o;
        if (gco.getClass() != getClass()) return false;
        if (gco.getObjectID().intValue() == 0 && getObjectID().intValue() == 0) return this == gco;
        return getObjectID().equals(gco.getObjectID());
    }

    @Override
    public int hashCode() {
        return getObjectID().hashCode();
    }

    public String getId(){
        return String.valueOf(objectID);
    }

    public String dateToStr(Date date){
        return new SimpleDateFormat(DATE_PATTERN).format(date);
    }

    public Date strToDate(String value) {
        try {
            return new SimpleDateFormat(DD_MM_YYYY_DOTS).parse(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
